//
//  UIAlertView+Entension.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/1.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#undef	UIAlertView_key_clicked
#define UIAlertView_key_clicked	"UIAlertView.clicked"

#import "UIAlertView+Entension.h"
#import <objc/runtime.h>

@implementation UIAlertView (Entension)

- (void)handlerClickedButton:(UIAlertView_block_self_index)aBlock
{
    self.delegate = self;
    objc_setAssociatedObject(self, UIAlertView_key_clicked, aBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    UIAlertView_block_self_index block = objc_getAssociatedObject(self, UIAlertView_key_clicked);
    !block ? : block(alertView, buttonIndex);
}
//断开关联
-(void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    objc_setAssociatedObject(self, @selector(handlerClickedButton:), nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

@end
